package com.qfedu.microuser.user.controller;

import com.qfedu.common.core.common.R;
import com.qfedu.common.core.entity.User;
import com.qfedu.microuser.user.service.UserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Classname UserController
 * @Description TODO
 * @Date 2025-09-23 10:58
 * @Created by 老任与码
 */
//@CrossOrigin
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/upload/avatar")
    public R uploadAvatar(MultipartFile file) {
        String path = userService.uploadAvatar(file);
        return R.success(path);
    }

    /**
     * 获取已登录的用户的用户信息
     * 注意：不用传用户id，从jwt获取即可
     *
     * @return
     */
    @GetMapping("/info")
    public R userInfo() {
        User user = userService.userInfo();
        return R.success(user);
    }
}
